﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class EditCompanyInfo : System.Web.UI.UserControl
    {
        DataTable dt;
        public string name;
        public string address;
        public string mobile;
        public string fax;
        public string email;
        public string website;
        public int slideid;
        public string filePathSlide;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                slideid = Convert.ToInt32(Request.QueryString["idslide"]);
                dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereID("tbl_CompanyInfo", "CompanyInfo_ID", slideid.ToString());

                name = dt.Rows[0]["CompanyInfo_Name"].ToString(); ;
                address = dt.Rows[0]["CompanyInfo_DiaChi"].ToString(); ;
                mobile = dt.Rows[0]["CompanyInfo_Mobile"].ToString(); ;
                fax = dt.Rows[0]["CompanyInfo_Fax"].ToString(); ;
                email = dt.Rows[0]["CompanyInfo_Email"].ToString(); ;
                website = dt.Rows[0]["CompanyInfo_Website"].ToString(); ;
                txtName.Text = name;
                txtAddress.Text = address;
                txtMobile.Text = mobile;
                txtFax.Text = fax;
                txtEmail.Text = email;
                txtWebsite.Text = website;
            }
            catch (Exception)
            {
                Response.Redirect("/Admin/error.htm");
            }
        }

        protected void btnUpdateSlide_Click(object sender, EventArgs e)
        {
            if (name != "")
            {
                    DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[6];
                    cl[0] = new DAL.DHelpers.Column("CompanyInfo_Name", txtName.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[1] = new DAL.DHelpers.Column("CompanyInfo_DiaChi", txtAddress.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[2] = new DAL.DHelpers.Column("CompanyInfo_Mobile", txtMobile.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[3] = new DAL.DHelpers.Column("CompanyInfo_Fax", txtFax.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[4] = new DAL.DHelpers.Column("CompanyInfo_Email", txtEmail.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[5] = new DAL.DHelpers.Column("CompanyInfo_Website", txtWebsite.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    string[] colWhere = new string[1];
                    colWhere[0] = "CompanyInfo_ID";

                    object[] colValue = new object[1];
                    colValue[0] = slideid;

                    DAL.DCollector.DBCollector.Instance.Update("tbl_CompanyInfo", cl, colWhere, colValue);
                    Response.Redirect("/Admin/Index.aspx?panel=5&sub=15");
            }
            else
            {
                Response.Write("<script>alert('Không thể để tên trống");
            }
        }
    }
}